package com.blog4j.system.api;

import com.blog4j.api.vo.OssBaseConfigVo;
import com.blog4j.api.vo.WebInfoVo;
import com.blog4j.api.vo.SystemBaseConfigVo;
import com.blog4j.common.annotation.OperationLog;
import com.blog4j.common.enums.ModuleTypeEnum;
import com.blog4j.common.enums.NoticeTypeEnum;
import com.blog4j.common.model.Result;
import com.blog4j.requestRate.annotation.RequestRate;
import com.blog4j.system.entity.OssExtendConfigEntity;
import com.blog4j.system.entity.WebInfoEntity;
import com.blog4j.system.service.NoticeService;
import com.blog4j.system.service.OssBaseConfigService;
import com.blog4j.system.service.SystemService;
import com.blog4j.system.service.WebInfoService;
import com.blog4j.system.vo.req.NoticeListReqVo;
import com.blog4j.system.vo.resp.NoticeRespVo;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author 98k灬
 * @version v1.0.0
 * @Description : 功能描述
 * @Create on : 2024/7/18 12:57
 **/
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ApiSystemController {
    private final SystemService systemService;
    private final WebInfoService webInfoService;
    private final OssBaseConfigService ossBaseConfigService;
    private final NoticeService noticeService;

    /**
     * 获取系统基础配置信息
     *
     * @return 系统基础配置信息
     */
    @RequestRate
    @OperationLog(module= ModuleTypeEnum.SYSTEM, description = "获取系统基础配置信息")
    @GetMapping("/getBaseSystemConfig")
    public Result getBaseSystemConfig() {
        SystemBaseConfigVo configVo = systemService.getBaseSystemConfig();
        return Result.ok(configVo);
    }

    /**
     * 获取网站配置信息
     *
     * @return 网站配置信息
     */
    @RequestRate
    @OperationLog(module= ModuleTypeEnum.SYSTEM, description = "获取网站配置信息")
    @GetMapping("/getWebInfo")
    public Result getWebInfo() {
        WebInfoEntity webInfo = webInfoService.getOne(null);
        WebInfoVo webInfoVo = new WebInfoVo();
        BeanUtils.copyProperties(webInfo, webInfoVo);
        return Result.ok(webInfoVo);
    }

    /**
     * 获取OSS基础配置信息
     *
     * @return OSS基础配置信息
     */
    @RequestRate
    @OperationLog(module= ModuleTypeEnum.SYSTEM, description = "获取OSS基础配置信息")
    @GetMapping("/getOssBaseConfig")
    public Result getOssBaseConfig() {
        OssBaseConfigVo ossBaseConfigVo = ossBaseConfigService.getOssBaseConfig();
        return Result.ok(ossBaseConfigVo);
    }

    /**
     * 获取OSS扩展配置信息
     *
     * @return OSS基础配置信息
     */
    @RequestRate
    @OperationLog(module= ModuleTypeEnum.SYSTEM, description = "获取OSS扩展配置信息")
    @GetMapping("/getOssExtendConfig")
    public Result getOssExtendConfig() {
        OssExtendConfigEntity ossBaseConfigVo = ossBaseConfigService.getOssExtendConfig();
        return Result.ok(ossBaseConfigVo);
    }

    /**
     * 获取系统公告信息
     *
     * @return 公告信息
     */
    @RequestRate
    @OperationLog(module= ModuleTypeEnum.SYSTEM, description = "获取系统公告信息")
    @GetMapping("/systemNotice")
    public Result systemNotice() {
        NoticeRespVo respVo = noticeService.systemNotice(NoticeTypeEnum.SYSTEM_NOTICE.getCode());
        return Result.ok(respVo);
    }

    /**
     * 获取全部公告信息
     *
     * @param reqVo 请求信息
     * @return 全部公告信息
     */
    @RequestRate
    @OperationLog(module= ModuleTypeEnum.SYSTEM, description = "获取全部公告信息")
    @PostMapping("/allNotice")
    public Result allNotice(@RequestBody @Valid NoticeListReqVo reqVo) {
        PageInfo<NoticeRespVo> pageInfo = noticeService.allNotice(reqVo);
        return Result.ok(pageInfo);
    }

    /**
     * 获取公告详情
     *
     * @param id 公共ID
     * @return 告详情
     */
    @RequestRate
    @OperationLog(module= ModuleTypeEnum.SYSTEM, description = "获取公告详情")
    @GetMapping("/noticeDetail/{id}")
    public Result noticeDetail(@PathVariable("id") Integer id) {
        NoticeRespVo respVo = noticeService.noticeDetail(id);
        return Result.ok(respVo);
    }
}
